<template>
	<view class="content">
		<loading v-if="showLoading"></loading>
		<view class="info-block">
			<template v-if="list.length>0">
				<view class="list-block">
					<view class="info-list" v-for="(item,index) in list" :key="item.id" 
					@click="navigate('/page_other/monetization/details?id='+item.id)">
						<view v-if="item.status==0"
							style="width: calc(50% - 40rpx); border-radius: 20rpx; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.3); position: absolute;height: 280rpx;">
							<view class="saleTime"
								style="color: #fff;font-weight:bold;font-size: 34rpx;text-align: center;">
								{{formatDate(item.saleTime)}} 售罄
							</view>
							<image
								src="https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/alliance/shouxin.png"
								class="img-shouqin" mode="aspectFill"></image>
						</view>
						<image
							src="https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/alliance/20240914111038.png"
							class="img-cover" mode="aspectFill"></image>
						<view class="describe-item">
							<view class="name">{{item.amount}}益联券</view>
							<view class="describe" v-if="item.businessName">{{item.businessName}}</view>
							<view class="wage">￥{{item.amount}}元</view>
						</view>
					</view>
				</view>
			</template>
			<view v-if="more==false&&list.length==0" class="empty">暂无数据</view>
			<view v-else-if="more==false&&list.length>0" class="empty">没有更多了</view>
		</view>
	</view>
</template>

<script>
	import {
		isMore
	} from '@/util/util.js'

	import {
		getStorage
	} from '@/util/auth.js';
	import {
		getCurrentUserList,
	} from '@/api/selling_coupons.js'
	export default {
	
		data() {
			return {
				conf: {
					page: 1,
					limit: 10,
				},
				more: true,
				list: []
			}
		},
		methods: {
			search() {
				this.getList(true)
			},
			handleRefresh() {
				this.conf.page = 1;
				this.more = true
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.getList(true)
			},
			formatDate(saleTime) {
			        const dateObj = new Date(saleTime);
			        const month = String(dateObj.getMonth() + 1).padStart(2, '0'); // Month is zero-indexed
			        const day = String(dateObj.getDate()).padStart(2, '0');
			        const hours = String(dateObj.getHours()).padStart(2, '0');
			        const minutes = String(dateObj.getMinutes()).padStart(2, '0');
			        const seconds = String(dateObj.getSeconds()).padStart(2, '0');
			        const formattedDate = `${month}-${day} ${hours}:${minutes}`;
			    
			        return formattedDate;
			},
			getList(refresh = false) {
				
				return getCurrentUserList(this.conf).then((res) => {
					let list = res.list || [];
					if (refresh) {
						this.list = list;
					} else {
						this.list = [...this.list, ...list]
					}
					this.more = isMore(this.conf.page, this.conf.limit, res.count)
				})
			}
		},
		 
		onPullDownRefresh() {
			this.handleRefresh();
		},
		onReachBottom() {
			if (this.more) {
				
				this.conf.page++;
				uni.showLoading({
					title: '加载中',
					mask: true
				})
			
				this.getList();
			}
		},
		async onLoad(e) {
			uni.showCustomLoading();
			Promise.all([this.getList(true)]).finally(() => {
				uni.hideCustomLoading()
			})
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		//height: calc(100vh - 160rpx);
		overflow-y: auto;
		position: relative;

		.search-block {
			width: 100%;
			height: 200rpx;
			// margin-top: 180rpx;
			background-image: linear-gradient(to right, #FF3432, #FF671A);
			padding: 30rpx;
		}

		.search-item {
			width: 100%;
			height: 70rpx;
			display: flex;

			.input-block {
				display: flex;
				background-color: #FFFFFF;
				border-radius: 50px;
				align-items: center;
				justify-content: space-between;
				width: 100%;
				padding: 6rpx 6rpx 6rpx 20rpx;

				.input-left {
					width: calc(100% - 140rpx);
					display: flex;

					image {
						width: 30rpx;
						height: 30rpx;
						// margin-right: 5rpx;
						margin: 7rpx 7rpx 0 0;
					}

					input {
						border-radius: 50px;
						width: 100%;

					}
				}

				.search {
					display: flex;
					justify-content: center;
					align-items: center;
					width: 130rpx;
					border-radius: 50rpx;
					height: 100%;
					padding-bottom: 5rpx;
					color: #FFFFFF;
					background: linear-gradient(90deg, #FF2F34 0%, #FF6B18 100%);
				}
			}
		}


		.info-block {
			display: flex;
			flex-direction: column;
			background: #F5F9FC;
			border-radius: 40rpx;
			margin-top: 2rpx;
			height: auto;
			position: relative;
			padding: 30rpx;
			min-height: 70vh;

			.list-block {
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;
				margin-bottom: 30rpx;


				.info-list {
					background: #fff;
					margin-top: 20rpx;
					border-radius: 20rpx;
					width: calc((100% - 20rpx) / 2);
					margin-right: 20rpx;
					height: 280rpx;
					
					.img-shouqin {
						margin-top: 10rpx;
						margin-left: 100rpx;
						width: 60%;
						height: 100rpx;
						border-radius: 20rpx 20rpx 0 0;
					}
					.img-cover{
						width: 100%;
						height: 150rpx;
						border-radius: 20rpx 20rpx 0 0;
					}

					.describe-item {
						padding:0 30rpx;

						.name {
							font-size: 28rpx;
							font-weight: bold;
							margin-bottom: 5rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}

						.describe {
							color: #828282;
							font-size: 28rpx;
							margin-bottom: 5rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}

						.wage {
							color: #FF2F34;
							font-weight: bold;
							font-size: 28rpx;

							.txt {
								font-size: 38rpx;
								margin-right: 10rpx;
							}
						}
					}
				}

				.info-list:nth-child(2n) {
					margin-right: 0;
				}
			}

			.empty {
				display: flex;
				justify-content: center;
			}
		}
	}
</style>